package test;

import java.util.Arrays;

public class QuickSort {

    public static void sort(int[] nums, int begin, int end) {

        int value = nums[begin];
        int i = begin ;
        int j = end;

        while (i < j) {
            while (nums[j] >= value && i < j) {
                j--;
            }
            nums[i] = nums[j];
            while (nums[i] <= value && i < j) {
                i++;
            }
            nums[j] = nums[i];
        }
        nums[i] = value;
        sort(nums, begin, i - 1);
        sort(nums, i + 1, end);
    }

    public static void main(String[] args) {
        int[] nums = new int[]{15, 6, 8, 2, 9, 30, 45, 35, 13, 17};
        sort(nums, 0, nums.length - 1);
        Arrays.stream(nums).forEach(num -> System.out.println(num + ","));
        System.out.println();
    }
}
